package com.leetcode_Onequestion;

/**
 * @Author jsh
 * @Date 2022/4/15 22:45
 * @Version 1.0
 *   -1870. 准时到达的列车最小时速
 */

public class leetcode_1870 {
    public static void main(String[] args) {

        int arr[] ={1,3,2};
        int a = minSpeedOnTime(arr,1.9);

        System.out.println(a);
    }

    public static int minSpeedOnTime(int[] dist, double hour) {
        if(dist.length-1 >= hour)
            return -1;
        int left = 1;
        int right = 10000000;
        int ans = 0;
        while (left <= right){
            int mid = (left +right) /2;
            double h = 0;
            for (int i = 0; i < dist.length-1; i++) {
                h += (dist[i]-1)/mid  + 1;
            }
            h += (double)(dist[dist.length-1])/mid;
            if (h <= hour){
                right = mid -1;
                ans = mid;
            }else {
                left =  mid +1;
            }
        }
        return ans;
    }
}
